package cn.edu.zjut.action;

import cn.edu.zjut.po.Address;
import cn.edu.zjut.po.Customer;
import cn.edu.zjut.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author XiaoFeng
 * @version 1.0
 * @Description Create by 2021/10/27 14:31
 */

public class UserAction extends ActionSupport {
    private Customer loginUser;
    private Address address;

    public Customer getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(Customer loginUser) {
        this.loginUser = loginUser;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public String login() {
        UserService userService = new UserService();
        if (userService.login(loginUser)) {
            return "success";
        }
        return "fail";
    }

    public String register() {
        UserService userServ = new UserService();
        if (userServ.register(loginUser)) {
            return "registerSuccess";
        }
        return "registerFail";
    }

    public String update() {
        UserService userService = new UserService();
        if (userService.update(loginUser)) {
            return "updateSuccess";
        }
        return "updateFail";
    }

    public String delete() {
        UserService userService = new UserService();
        if (userService.delete(loginUser)) {
            return "deleteSuccess";
        }
        return "deleteFail";
    }

    public String addAddr() {
        UserService userServ = new UserService();
        if (userServ.addAddr(loginUser, address))
            return "success";
        else
            return "fail";
    }
    public String delAddr() {
        UserService userServ = new UserService();
        if (userServ.delAddr(loginUser))
            return "success";
        else
            return "fail";
    }

}
